<?php
session_start();
$username=$_SESSION['username'];
$connetc=mysql_connect("localhost","root","");
mysql_select_db("shenji",$connetc);
mysql_query("set names utf8");
$sql4="select * from user where username='$username'";

$result4=mysql_query($sql4);
$row4=mysql_num_rows($result4);


if($row4==0){
	echo "<script>alert('用户不存在，请重新登录！');top.location.href='./login.php'</script>";
}


$id=intval($_GET['id']);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.6.3.min.js"></script>
</head>
<body>
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">用户管理</a></li>
	<?php
	if($id==null){
	?>
	<li><a href="#">添加用户</a></li>
	<?php
	}else{
	?>	
	<li><a href="#">编辑用户</a></li>
	<?php	
	}
	?>
    </ul>
    </div>
    
    <div class="formbody">
    <div class="formtitle"><span>基本信息</span></div>
    <form method="post" action="insert_user_commit.php">
    <ul class="forminfo">
    <li><label>用户名</label><input name="username" id="username" type="text" onblur="insert_user();" class="dfinput" value="<?php echo $row['username'];?>"/><i style="display:none;color:#f00;" id="yz_user">用户名由中文、字母、数字组成;且首位不能为数字长度在3~10个字符</i>
    </li>
    <li><label>密码</label><input name="password" id="password" type="password" class="dfinput" value="<?php echo $row['password'];?>" onblur="insert_pass();"/><i style="display:none;color:#f00;" id="yz_pass">密码由字母、数字组成;且长度在6~32个字符</i></li>
    <li><label>用户状态</label>
		<select  name="status" id="status">
			<option value="1"  <?php echo (isset($row)&&$row['status']==1)?'selected=selected':'';?>>普通用户</option>
			<option value="0"  <?php echo (isset($row)&&$row['status']==0)?'selected=selected':'';?>>管理员</option>
		</select>
	</li>
    <li><label>&nbsp;</label><input type="submit" name="submit" class="btn" value="确认保存"/></li>
    </ul>
	</form>
    </div>
</body>
</html>
<script>

    function insert_user(){
	var username=/^[\u4e00-\u9fa5a-zA-Z]{1}[\u4e00-\u9fa5A-Za-z0-9]{2,9}$/;
	if(username.test($('#username').val())){
		$("#yz_user").hide();
	}else{
		$("#yz_user").show();
	}
	}

    function insert_pass(){
	var password=/^[a-zA-Z0-9_]{6,16}$/;
	if(password.test($('#password').val())){
		$("#yz_pass").hide();
	}else{
		$("#yz_pass").show();
	}
	}
$(function(){

	$("#username").focus(function(){
		$("#yz_user").hide();
	})
	$("#password").focus(function(){
		$("#yz_pass").hide();
	})
})
	$(function(){
		$('.btn').bind('click',function(event){
			var username=/^[\u4e00-\u9fa5a-zA-Z]{1}[\u4e00-\u9fa5A-Za-z0-9]{2,9}$/;
			
			if(username.test($('#username').val())){
				$("#yz_user").hide();
				
			}else{
				$("#yz_user").show();
				
				return false;
			}			
		})
	})
		$(function(){
		$('.btn').bind('click',function(event){
			
			var password=/^[a-zA-Z0-9_]{6,16}$/;
			if(password.test($('#password').val())){
				
				$("#yz_pass").hide();
			}else{
				
				$("#yz_pass").show();
				return false;
			}			
		})
	})

 $(document).ready(function(){
	  
	  var username="<?php echo $_SESSION['username']; ?>";
	  if(username==null||username.length==0){		  
		 window.top.location.href="../login.php";
	  }
	  
  })
 	/*function tijiao(){
	var username=/^[a-zA-Z0-9_]{3,16}$/;
	var password=/^[a-zA-Z0-9_]{6,16}$/;
	if(username.test($('#username').val())&&password.test($('#password').val())){
		alert("用户名或者密码格式错误！");
	}
	}*/
</script>

